package com.zhengxing.jienci.user.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhengxing.jienci.user.domain.PointDetail;
import com.zhengxing.jienci.user.domain.PointRule;
import com.zhengxing.jienci.user.mapper.PointDetailMapper;
import com.zhengxing.jienci.user.mapper.PointRuleMapper;
import com.zhengxing.jienci.user.service.IPointRuleService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 积分规则 服务实现类
 * </p>
 *
 * @author yyh
 * @since 2020-12-01
 */
@Service
public class PointRuleServiceImpl extends ServiceImpl<PointRuleMapper, PointRule> implements IPointRuleService {

	@Autowired
	private PointRuleMapper prMapper;
	
	@Autowired
	private PointDetailMapper pdMapper;
	
	@Override
	public List<PointRule> pointRuleListForMyself(String userId, String nowDate) {
		List<PointRule> pointRuleList = prMapper.selectList(null);
		pointRuleList.forEach(pointRule -> {
			Map<String, Object> columnMap = new HashMap<>();
			columnMap.put("operation", pointRule.getOperation());
			columnMap.put("user_id", userId);
			columnMap.put("create_time", nowDate);
			List<PointDetail> pdList = pdMapper.selectByMap(columnMap);
			if(pdList == null)
				pointRule.setRemain(0);
			pointRule.setRemain(pointRuleList.size());
		});
		return pointRuleList;
	}

}
